'''
Created on May 31, 2010

@author: pedro
'''
import logging, re, utils.htmlutils as http

log = logging.getLogger("resolvers")

def regexFinder(regex):
  """
  Create a finder that returns all matches for a regex
  """
  def finder(page):
    found = re.compile(regex).findall(page)
    log.debug("Found links: %s" % str(found))
    return found
  return finder

def processSourcePage(page, processor):
  """
  Will call the processor with the first src="(.+?)" page found
  """
  url = re.compile('src="(.+?)"').findall(page)
  log.debug("Found stream page urls: %s" % str(url))
  url = url[0].replace('&amp;', '&')
  return processor(http.get(url))

